﻿
function showUrlInDialog(url, options) {
    options = options || {};
    var tag = $("<div></div>"); //This tag will the hold the dialog content.
    $.ajax({
        url: url,
        type: (options.type || 'GET'),
        beforeSend: options.beforeSend,
        error: options.error,
        complete: options.complete,
        success: function (data, textStatus, jqXHR) {
            if (typeof data == "object" && data.html) { //response is assumed to be JSON
                tag.html(data.html).dialog({ modal: true, title: "People who like this" }).dialog('open');
            } else { //response is assumed to be HTML
                tag.html(data).dialog({ modal: true, title: "People who like this" }).dialog('open');
            }
            $.isFunction(options.success) && (options.success)(data, textStatus, jqXHR);
        }
    });

}


var copytoclip = 1;
function HighlightAll(maaUrl) {
    var tempval = eval(maaUrl);
    tempval.focus();
    tempval.select();
    if (document.all && copytoclip == 1) {
        therange = tempval.createTextRange();
        therange.execCommand("Copy");
        window.status = "Contents highlighted and copied to clipboard!";
        setTimeout("window.status=''", 1800);
    }

}


var chkLatestUpdates;
var chkInboxMsgs;
var chkNotifications;
var chkStats;
var chkPagenotifications;
function fnCheckForStats() {
    try {
        var dataObjToPost = {
            //  memberID: $("#memIDForJS").text(),
            pm: "sts",
            lastReqTime: $("#srvReqTimeForNotifications").text()
        };
        $.ajax({
            type: "POST",
            url: "/chkAlNot.aspx",
            data: dataObjToPost,
            dataType: "html",
            async: true,
            success: function (replyMsg) {
                if (replyMsg.toLowerCase().indexOf("wallpostloginpageforidentification") != -1) {
                    $("div.updatesSinceLogin").text("It seems you are logged out...");
                    window.location.href = "/member-login.aspx";
                }
                else if (replyMsg == "0") {
                        // $("div.Icon3Text").css("display", "none")
                    $("div.note").css("display", "none");
                }

                else {
                    //$("div.Icon3Text").text(replyMsg);
                    $("div.note").css("display", "block");
                    $("div.note").text(replyMsg);
                }
                chkStats = setTimeout("fnCheckForStats()", 20000);
            },
            error: function (errMsg) {
                chkStats = setTimeout("fnCheckForStats()", 20000);
            }
        });
    }
    catch (ex) {
        chkLatestUpdates = setTimeout("fnCheckForStats()", 10000);
    }
}
function fnCheckForLatestUpdates() {
    try {
        var dataObjToPost = {
            pm: "lu",
            updType: $("div.updatesSinceLogin").attr("dbParam"),
            lastReqTime: $("#lastSrvReqTime").text()
        };
        $.ajax({
            type: "POST",
            url: "/chkAlNot.aspx",
            data: dataObjToPost,
            dataType: "html",
            async: true,
            success: function (replyMsg) {
                if (replyMsg.toLowerCase().indexOf("wallpostloginpageforidentification") != -1) {
                    $("div.updatesSinceLogin").text("It seems you are logged out...");
                    window.location.href = "/member-login.aspx";
                }
                else {
                    $("div.updatesSinceLogin").html(replyMsg);
                }
                chkLatestUpdates = setTimeout("fnCheckForLatestUpdates()", 20000);
            },
            error: function (errMsg) {
                chkLatestUpdates = setTimeout("fnCheckForLatestUpdates()", 20000);
            }
        });
    }
    catch (ex) {
        chkLatestUpdates = setTimeout("fnCheckForLatestUpdates()", 20000);
    }
}
function fnCheckForInboxMsgs() {
    try {
        var dataObjToPost = {
            //  memberID: $("#memIDForJS").text(),
            pm: "inb",
            lastReqTime: $("#srvReqTimeForNotifications").text()
        };
        $.ajax({
            type: "POST",
            url: "/chkAlNot.aspx",
            data: dataObjToPost,
            dataType: "html",
            async: true,
            success: function (replyMsg) {
                if (replyMsg.toLowerCase().indexOf("wallpostloginpageforidentification") != -1) {
                    $("div.updatesSinceLogin").text("It seems you are logged out...");
                    window.location.href = "/member-login.aspx";
                }
                else if (replyMsg == "0") {
                        // $("div.Icon3Text").css("display", "none")
                    $("div.note3").css("display", "none");
                }

                else {
                    //$("div.Icon3Text").text(replyMsg);
                    $("div.note3").css("display", "block");
                    $("div.note3").text(replyMsg);
                }
                chkLatestUpdates = setTimeout("fnCheckForInboxMsgs()", 10000);
            },
            error: function (errMsg) {
                chkLatestUpdates = setTimeout("fnCheckForInboxMsgs()", 10000);
            }
        });
    }
    catch (ex) {
        chkLatestUpdates = setTimeout("fnCheckForInboxMsgs()", 10000);
    }
}

function fnCheckForNotification() {
    try {
        var dataObjToPost = {
            //   memberID: $("#memIDForJS").text(),
            pm: "noti",
            lastReqTime: $("#srvReqTimeForNotifications").text()
        };
        $.ajax({
            type: "POST",
            url: "/chkAlNot.aspx",
            data: dataObjToPost,
            dataType: "html",
            async: true,
            success: function (replyMsg) {
                var replyObj = $("<div/>").html(replyMsg);
                if (replyMsg.toLowerCase().indexOf("wallpostloginpageforidentification") != -1) {
                    $("div.updatesSinceLogin").text("It seems you are logged out...");
                    window.location.href = "/member-login.aspx";
                }
                else if ($(replyObj).find("#ajaxNotifCnt").text() == "0") {
                    $("div.note2").css("display", "none");
                }
                else {
                    //  $("div.Icon1Text").text(replyMsg);
                    $("div.note2").css("display", "block");
                    $("div.note2").text($(replyObj).find("#ajaxNotifCnt").text());
                    $("div.notipopupC div.notificationsWrap div.nWdw ul").html($(replyObj).find("#ajaxNotifDescr").html());
                }
                chkNotifications = setTimeout("fnCheckForNotification()", 20000);
                $(replyObj).remove();
            },
            error: function (errMsg) {
                chkNotifications = setTimeout("fnCheckForNotification()", 20000);
            }
        });
    }
    catch (ex) {
        chkNotifications = setTimeout("fnCheckForNotification()", 20000);
    }
}


//function for page notifications to admin
function fnCheckForPageStats(id) {

    try {
        var dataObjToPost = {
            pm: "pgSt",
            pgId: id
        };

        $.ajax({
            type: "POST",
            url: "/chkAlNot.aspx",
            data: dataObjToPost,
            dataType: "html",
            async: true,
            success: function (replyMsg) {

                if (replyMsg == "0") {
                    $("div.notepg").css("display", "none");
                }
                else {
                    $("div.notepg").css("display", "block");
                    $("div.notepg").text(replyMsg);
                }
                chkPagenotifications = setTimeout("fnCheckForPageStats(" + id + ")", 20000);

            },
            error: function (errMsg) {
                chkPagenotifications = setTimeout("fnCheckForPageStats(" + id + ")", 20000);
            }
        });
    }
    catch (ex) {

        chkPagenotifications = setTimeout("fnCheckForPageStats(" + id + ")", 20000);
    }

}  //End of fnCheckForPageStats


function addFriend(id, id1) {
    $("div#addfrnd" + id1).css("display", "none");
    $("div#pendfrnd" + id1).css("display", "block");
    var string = 'a=af&frId=' + id;
    $.ajax({
        type: "POST",
        url: "/AutoNames.aspx",
        data: string,
        success: function (respMsg) {

        }
    });


}



function addFriend1(id, id1) {
    $("div#addfrnd" + id1 + id).css("display", "none");
    $("div#pendfrnd" + id1 + id).css("display", "block");
    var string = 'a=af&frId=' + id;
    $.ajax({
        type: "POST",
        url: "/AutoNames.aspx",
        data: string,
        success: function (respMsg) {

        }
    });


}



function cancelReq(id, id1) {
    $("div#addfrnd" + id1).css("display", "block");
    $("div#pendfrnd" + id1).css("display", "none");
    var string = 'memberId=' + id;
    $.ajax({
        type: "POST",
        url: "/DeleteContact.aspx",
        data: string,
        success: function (respMsg) {

        }
    });
}


function cancelReq1(id, id1) {
    $("div#addfrnd" + id1 + id).css("display", "block");
    $("div#pendfrnd" + id1 + id).css("display", "none");
    var string = 'memberId=' + id;
    $.ajax({
        type: "POST",
        url: "/DeleteContact.aspx",
        data: string,
        success: function (respMsg) {

        }
    });
}


function AddToGrpFG(id, q, memId, i) {
    var string = 'a=addMem&Id=' + id + '&memberId=' + memId;

    $.ajax({
        type: "POST",
        url: "/DeleteGroupMember.aspx",
        data: string,
        cache: false,
        success: function (rtMsg) {

            if (rtMsg == 'INSERTED') {

                $("#addtogrp" + q + i).addClass("current");
            }
            else if (rtMsg == 'DELETED') {

                $("#addtogrp" + q + i).removeClass("current");
            }
        }
    });
}


function AddToGrpFG1(id, q, memId, i) {
    var string = 'a=addMem&Id=' + id + '&memberId=' + memId;

    $.ajax({
        type: "POST",
        url: "/DeleteGroupMember.aspx",
        data: string,
        cache: false,
        success: function (rtMsg) {

            if (rtMsg == 'INSERTED') {

                $("#addtogrp" + q + i + id).addClass("current");
            }
            else if (rtMsg == 'DELETED') {

                $("#addtogrp" + q + i + id).removeClass("current");
            }
        }
    });
}

function show_pageAvail(str) {

    var string = 'a=pgAv&pageUrl=' + str;
    $.ajax({
        type: "POST",
        url: "/JqueryPageGroup.aspx",
        data: string,
        cache: false,
        success: function (rtMsg) {

            if ((rtMsg == 'NO') && (str != '')) {
                document.getElementById("continue").value = "0";
                document.getElementById("avn").style.display = "block";
                document.getElementById("av").style.display = "none";
                document.getElementById("submit").disabled = true;
            }
            else if ((rtMsg == 'YES') && (str != '')) {
                document.getElementById("continue").value = "1";
                document.getElementById("av").style.display = "block";
                document.getElementById("avn").style.display = "none";
                document.getElementById("submit").disabled = false;
            }
            else {
                document.getElementById("continue").value = "0";
                document.getElementById("av").style.display = "none";
                document.getElementById("avn").style.display = "none";
                document.getElementById("submit").disabled = true;
            }
        }
    });
}

function addTheme(the) {
    var postedParameters = "";
    postedParameters = "t=adThe&theme=" + the;
    $.ajax({
        type: "POST",
        url: "/AddCommForPhPrMemPh.aspx",
        data: postedParameters,
        success: function (ss) {
        }
    });
}


function addThemeP(the) {
    var postedParameters = "";
    postedParameters = "t=adTheP&theme=" + the;
    $.ajax({
        type: "POST",
        url: "/AddCommForPhPrMemPh.aspx",
        data: postedParameters,
        success: function (ss) {

        }
    });

}